<!-- 继承blog/base.html 文件 -->
{% extends "blog/base.html" %}
<!-- 加载自定义标签 -->
{% load blog_tags %}
<!-- 使用此处标题块内容替换blog/base.html文件中标题块 -->
{% block title %}{{ post.title }}{% endblock %}
<!-- 使用此处内容块代码替换blog/base.html文件中内容块-->
{% block content %}
<h1>{{ post.title }}</h1>
 <p class="date">
Published {{ post.publish }} by {{ post.author }}
 </p >
{{ post.body|markdown }}
 <!-- 增加分享文章链接，链接地址自动根据路由名称生成 -->
<p>
<a href=" "blog:post_share" post.id %}">
 Share this post
</a >
<!-- 显示相似文章 -->
<!-- 标题 -->
<h2>Similar posts</h2>
{% for post in similar_posts %} 
   <p>
   <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
   </p >
{% empty %}
   There are no similar posts yet.
{% endfor %}
{% with comments.count as total_comments %}
   <h2>
  <!-- pluralize 过滤器叫做复数过滤器，当前面的数量是大于1的则自动为comment添加
 s，适用于英文-->
       {{ total_comments }} comment{{ total_comments|pluralize }}
   </h2>
{% endwith %}
{% for comment in comments %}
<div class="comment">
   <p class="info">
 <!-- forloop.counter 标签自动生成循环元素的序号 -->
   Comment {{ forloop.counter }} by {{ comment.name }}
   {{ comment.created }}
   </p>
   {{ comment.body|linebreaks }}
</div>   
{% empty %}
   <p>There are no comments yet.</p>
{% endfor %}
{% if new_comment %}
<h2>Your comment has been added.</h2>
<!-- 否则显示添加新评论并显示评论表单-->
{% else %}
   <h2>Add a new comment</h2>
<!-- 评论表单 -->
   <form method="post">
 <!-- 根据后端评论表单自动生成前端评论表单 -->
       {{ comment_form.as_p }}
 <!-- 防止远程跨域劫持攻击 -->
       {% csrf_token %}
 <!-- 提交评论按钮 -->
   <p><input type="submit" value="Add comment"></p>
   </form>
{% endif %}   
{% endblock %}
